-- googlebot.lua - Sam Collins

-- Use existing bot? "true" is yes, and "false" is no.
use_existing_bot = false;

-- The name for the bot, set to existing bot if above is "true".
set_bot_name = "GoogleBot"

-- Replace with your e-mail address.
set_bot_email = "voidboi@gmail.com";

-- Change this too, if you want; Bot-description.
set_bot_desc = "Type .ghelp for GoogleBot help commands.";


function Main()
-- Check if script should add a new bot.
if (not use_existing_bot or use_existing_bot == 0) then
-- Add new bot.
VH:AddRobot(set_bot_name, 10, set_bot_desc, "Bot ", set_bot_email, "0");
end;
end

function UnLoad()
    VH:DelRobot(set_bot_name);
end;

function VH_OnParsedMsgChat(nick, data)
local searchstring;
if (string.find(data, "^%.google")) then
    _,_,searchstring = string.find(data, "^%.google".."%s(.+)")
    VH:SendDataToAll("<"..set_bot_name.."> "..nick..": http://www.google.com/search?q="..string.gsub(searchstring, " +", "+").."|", 1, 10)
    return 0
elseif (string.find(data, "^%.glucky")) then
    _,_,searchstring = string.find(data, "^%.glucky".."%s(.+)")
    VH:SendDataToAll("<"..set_bot_name.."> "..nick..": http://www.google.com/search?q="..string.gsub(searchstring, " +", "+").."&btnI=I'm+Feeling+Lucky|", 1, 10)
    return 0
elseif (string.find(data, "^%.img")) then
    _,_,searchstring = string.find(data, "^%.img".."%s(.+)")
    VH:SendDataToAll("<"..set_bot_name.."> "..nick..": http://images.google.com/images?q="..string.gsub(searchstring, " +", "+").."|", 1, 10)
    return 0
elseif (string.find(data, "^%.ghelp")) then
    MsgHelp(nick);
    return 0
end

return 1;
end

function VH_OnParsedMsgPM(from, data, to)
if (string.find(to, "^GoogleBot$")) then
    MsgPM(from, "blerrrrrrrrr");
    return 0;
end
    
return 1;
end;

-- Show help-message to user.
function MsgHelp (user)
local help;
help = "The following GoogleBot commands are available to you:\n"..
"\n.ghelp - This help file\n\n"..
".google <keywords> - shows google search link in main chat.\n\n"..
".img <keywords> - shows google image search link in main chat.\n\n"..
".glucky <keywords> - shows google \"I'm feeling lucky\" search link in main chat.\n\n";

MsgPrivate(user, help);
return 1;
end;


-- sends PM to specified user
function MsgPM(user, data)
return VH:SendDataToUser("$To: "..user.." From: "..set_bot_name.." $<"..set_bot_name.."> "..data.."|", user);
end

-- Sends private messages to specified user.
function MsgPrivate(user, data)
return VH:SendDataToUser("<"..set_bot_name.."> "..data.."|", user);
end;